package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IOtherFragmentModel;
import com.wgts.wgts.mvp.presenter.IOtherFragmentPresenter;
import com.wgts.wgts.mvp.view.IOtherFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.AppModleRequest;
import com.wgts.wgts.netmodle.req.SearchShopListRequest;
import com.wgts.wgts.netmodle.resp.AppModleEntity;
import com.wgts.wgts.netmodle.resp.ClassBannerEntity;
import com.wgts.wgts.netmodle.resp.GoodProductEntity;
import com.wgts.wgts.netmodle.resp.SearchShopResultEntity;

import java.util.List;

public class OtherFragmentPresenter implements IOtherFragmentPresenter {

    private IOtherFragmentModel model;

    private IOtherFragmentView view;

    private int pageIndex = 1;

    private int pageSize = 20;

    private Integer typeId;


    public OtherFragmentPresenter(IOtherFragmentModel model, IOtherFragmentView view) {
        this.model = model;
        this.view = view;
    }


    @Override
    public void initHead(int scene, int parentTypeId) {
        AppModleRequest request = new AppModleRequest();
        request.scene = String.valueOf(scene);
        request.parentTypeId = parentTypeId;
        model.initHead(request, new HttpResultSubscriber<List<AppModleEntity>>() {
            @Override
            public void onSuccess(List<AppModleEntity> appModleEntities) {
                view.inithead(appModleEntities);
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void initGoodProduct(Integer typeId) {

        pageIndex = 1;

        this.typeId = typeId;
        model.goodProduct(typeId, pageIndex, pageSize, new HttpResultSubscriber<GoodProductEntity>() {
            @Override
            public void onSuccess(GoodProductEntity entity) {
                if(entity.list.size() < pageSize){
                    view.initProductList(entity, true);
                }else {
                    view.initProductList(entity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });


    }

    @Override
    public void moreGoodProduct() {
        model.goodProduct(typeId, pageIndex, pageSize, new HttpResultSubscriber<GoodProductEntity>() {
            @Override
            public void onSuccess(GoodProductEntity entity) {
                if(entity.list.size() < pageSize){
                    view.moreProductList(entity, true);
                }else {
                    view.moreProductList(entity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });

    }

    @Override
    public void initBanner(Integer typeId) {
        model.initBanner(typeId, new HttpResultSubscriber<List<ClassBannerEntity>>() {
            @Override
            public void onSuccess(List<ClassBannerEntity> bannerEntities) {
                view.initBanner(bannerEntities);
            }

            @Override
            public void _onError(int status, String msg) {
                view.onError(status, msg);
            }
        });
    }
}
